﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;

namespace QLTV.Forms.KhaiBao
{
    public partial class frmDanhSachHetHan : DevExpress.XtraEditors.XtraForm
    {
        public frmDanhSachHetHan()
        {
            InitializeComponent();
        }
        private void frmDanhSachHetHan_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'dsCanhBao.OnVacationContract' table. You can move, or remove it, as needed.
            this.onVacationContractTableAdapter.Fill(this.dsCanhBao.OnVacationContract);
            // TODO: This line of code loads data into the 'dsCanhBao.OnBoardContract' table. You can move, or remove it, as needed.
            this.onBoardContractTableAdapter.Fill(this.dsCanhBao.OnBoardContract);
            if (temp == "1")
            {
                if (Program.language == "en")
                {
                    txt9.Text = "3 Months left warning";
                }
                else
                {
                    txt9.Text = "Cảnh báo trước 3 tháng";
                }
                txt12.Visible = false;
                color12.Visible = false;
                this.onBoardCertificateTableAdapter.Fill(this.dsCanhBao.OnBoardCertificate);
            }
            else if (temp == "2")
            {
                if (Program.language == "en")
                {
                    txt9.Text = "3 Months left warning";
                }
                else
                {
                    txt9.Text = "Cảnh báo trước 3 tháng";
                }
                txt12.Visible = false;
                color12.Visible = false;
                this.onBoardVisaTableAdapter.Fill(this.dsCanhBao.OnBoardVisa);
            }
            else if (temp == "3")
            {
                if (Program.language == "en")
                {
                    txt9.Text = "9 Months left warning";
                }
                else
                {
                    txt9.Text = "Cảnh báo trước 9 tháng";
                }
                txt12.Visible = true;
                color12.Visible = true;
                if (Program.language == "en")
                {
                    txt12.Text = "12 Months left warning";
                }
                else
                {
                    txt12.Text = "Cảnh báo trước 1 năm";
                }

                this.tadOnVacationCertificate.Fill(this.dsCanhBao.OnVacationCertificate);
            }
            else
            {
                if (Program.language == "en")
                {
                    txt9.Text = "9 Months left warning";
                }
                else
                {
                    txt9.Text = "Cảnh báo trước 9 tháng";
                }
                txt12.Visible = true;
                color12.Visible = true;
                if (Program.language == "en")
                {
                    txt12.Text = "12 Months left warning";
                }
                else
                {
                    txt12.Text = "Cảnh báo trước 1 năm";
                }

                this.onvacationVisaTableAdapter.Fill(this.dsCanhBao.OnvacationVisa);
            }

            this.tblRankTableAdapter.Fill(this.dsRanking.tblRank);


        }

        private void gridOnboardCertificate_CustomColumnDisplayText(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnDisplayTextEventArgs e)
        {
            if (e.Column == colStt && e.RowHandle > -1)
            {
                e.DisplayText = (e.RowHandle + 1).ToString();
            }
        }

        private void viewOnBoardVisa_CustomColumnDisplayText(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnDisplayTextEventArgs e)
        {
            if (e.Column == colSTT2 && e.RowHandle > -1)
            {
                e.DisplayText = (e.RowHandle + 1).ToString();
            }
        }

        private void viewOnVacationCertificate_CustomColumnDisplayText(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnDisplayTextEventArgs e)
        {
            if (e.Column == stt3 && e.RowHandle > -1)
            {
                e.DisplayText = (e.RowHandle + 1).ToString();
            }
        }

        private void viewOnVacationVisa_CustomColumnDisplayText(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnDisplayTextEventArgs e)
        {
            if (e.Column == stt4 && e.RowHandle > -1)
            {
                e.DisplayText = (e.RowHandle + 1).ToString();
            }
        }
        public string temp { get; set; }


        private void barButtonItem1_ItemClick_1(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            SaveFileDialog f = new SaveFileDialog();
            f.Filter = "Excel (*.xls)|*.xls";
            if (f.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                if (temp == "1")
                {
                    viewOnboardCertificate.ExportToXls(f.FileName);
                }
                else if (temp == "2")
                {
                    viewOnBoardVisa.ExportToXls(f.FileName);
                }
                else if (temp == "3")
                {
                    viewOnVacationCertificate.ExportToXls(f.FileName);
                }
                else if (temp == "4")
                {
                    viewOnVacationVisa.ExportToXls(f.FileName);
                }
                else if (temp == "5")
                {
                    viewOnBoardContract.ExportToXls(f.FileName);
                }
                else if (temp == "6")
                {
                    viewOnVacationContract.ExportToXls(f.FileName);
                }
            }

        }
        private void checkEdit1_CheckedChanged_1(object sender, EventArgs e)
        {
            //viewOnboardCertificate
            if (temp == "1")
            {
                if (checkEdit1.Checked)
                {
                    onBoardCertificateBindingSource.Filter = "";
                }
                else
                    onBoardCertificateBindingSource.Filter = "monthLeft <=3";
            }
            //viewOnBoardVisa
            else if (temp == "2")
            {
                if (checkEdit1.Checked)
                    onBoardVisaBindingSource.Filter = "";
                else

                    onBoardVisaBindingSource.Filter = "monthLeft <=3";
            }
            //viewOnVacationCertificate
            else if (temp == "3")
            {
                if (checkEdit1.Checked)
                    onVacationCertificateBindingSource.Filter = "";
                else

                    onVacationCertificateBindingSource.Filter = "monthLeft <=12";
            }
            // viewOnVacationVisa
            else if (temp == "4")
            {
                if (checkEdit1.Checked)
                    onvacationVisaBindingSource.Filter = "";
                else
                    onvacationVisaBindingSource.Filter = "monthLeft <=12";
            }
            else if (temp == "5")
            {
                if (checkEdit1.Checked)
                    onBoardContractBindingSource.Filter = "";
                else
                    onBoardContractBindingSource.Filter = "monthLeft <=6";
            }
            else if (temp == "6")
            {
                if (checkEdit1.Checked)
                    onVacationContractBindingSource.Filter = "";
                else
                    onVacationContractBindingSource.Filter = "monthLeft <=6";
            }
        }

        private void viewOnBoardContract_CustomColumnDisplayText(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnDisplayTextEventArgs e)
        {
            if (e.Column == colSTTContract2 && e.RowHandle > -1)
            {
                e.DisplayText = (e.RowHandle + 1).ToString();
            }
        }

        private void viewOnVacationContract_CustomColumnDisplayText(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnDisplayTextEventArgs e)
        {
            if (e.Column == colSTTContract && e.RowHandle > -1)
            {
                e.DisplayText = (e.RowHandle + 1).ToString();
            }
        }
    }
}